package Demo1;

public class T11 {
    //    利用多线程 计算大数相加
    private static long result = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
//                同步代码块加锁 保证线程安全
                for (long i = 1; i <= 5000000; i++) {
                    result += i;
            }
        });
        Thread thread1 = new Thread(()->{
                for (long i = 500001; i <= 10000000; i++) {
                    result += i;
                }

        });
        thread.start();
        thread1.start();

        thread1.join();
        thread.join();
        System.out.println("result="+result);
    }
}